﻿
#region Usings

using FasterWPF;
using FasterWPFDemo.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Thriple.Controls;
using FasterWPF.Selectors;

#endregion

namespace FasterWPFDemo
{
    public partial class TabItem10 : UserControl, IUserControlGuid
    {
        #region Actions
        
        private void BuildAndStoreActions(ExampleUserControl usc, UserControlRegion epres)
        {
            //Store Action in Global Store on Application object
            GlobalStoreService.PutInGlobalStore(GlobalStoreService.TabControlGuids.Ten, "RegionOneAction1", new Action<object, RoutedEventArgs>((o, ev) =>
            {
                MessageBox.Show("I was just clicked: Remove me!");

                //Border buttonInsideUserControl = usc.GetChildFromParent<Border, UserControl>(_userCtlGuid, 0, 1);
                ////UnHook click event on button
                //buttonInsideUserControl.DisposeEvents<Border>();

                usc.DisposeEventsOnAllParents();

                //Remove UserControl from UserControlRegion
                epres.RemoveAll<Border>();

            }));

            //This should be checked for MEMORY LEAKS - is ExampleUserControl being kept alive?
            GlobalStoreService.PutInGlobalStore(GlobalStoreService.TabControlGuids.Ten, "RegionOneAction2", new Action<object, RoutedEventArgs>((o, ev) =>
            {
                MessageBox.Show("I was just clicked: Add me!");

                if (epres.GetCompositeLookupDictionary<Border>() != null && epres.GetCompositeLookupDictionary<Border>().Count > 0)
                {
                    //Border buttonInsideUserControl = usc.GetChildFromParent<Border, UserControl>(_userCtlGuid, 0, 1);

                    ////UnHook click event on button
                    //buttonInsideUserControl.DisposeEvents<Border>();
                    
                    usc.DisposeEventsOnAllParents();

                    //If it hasn't already been removed, remove UserControl from UserControlRegion
                    epres.RemoveAll<Border>();
                }

                ExampleUserControl2 uscNext = new ExampleUserControl2(_userCtlGuid);
                epres.AddUserControl(uscNext);



            }));
        }

        #endregion
    }
}
